package com.cqut.forum.aspect.imp;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

import com.cqut.forum.aspect.ModuleInfoAspect;
import com.cqut.forum.entity.User;
import com.cqut.forum.service.ModuleService;

/**
 * ModuleInfoAspect实现类
 * @author yangxun
 *
 */

@Aspect
@Component
public class ModuleInfoAspectImp implements ModuleInfoAspect{
	@Resource
	HttpServletRequest request;
	@Resource
	ModuleService moduleService;
	
	@SuppressWarnings("unchecked")
	@Override
	@AfterReturning(returning="user",pointcut="execution(public * com.cqut.forum.service.imp.UserServiceImp.login(..))")
	public void moduleInfo(User user) {
		System.out.println("+++++++++++++++start system style handle++++++++++++++++");
		ServletContext application = request.getSession().getServletContext();
		List<Map<String,Object>> ss = (List<Map<String, Object>>) application.getAttribute("ss");
		if(ss!=null)return;
		
		//ss = moduleService.loadModuleInfos();
		ss = moduleService.loadModules();
		application.setAttribute("ss", ss);
		System.out.println("+++++++++++++++end system style handle++++++++++++++++");
	}
}
